package grid.items;

import java.io.IOException;
import java.io.Serializable;

import blockworld.Tile;

public class Body implements Tile, Serializable {
	
	/**
	 * Hack, louis would kill us for this
	 * 8150338305392574748
	 * -5929501020475851008
	 */
	private static final long serialVersionUID = -5929501020475851008l;
	
	
	
	int HP=10;
	String name;
	int type;
	String team;
	public Body(String name,String team, int type)
	{
		this.name=name;
		this.type=type;
		this.team=team;
	}

	public static final int ROCK = 0;
	public static final int PAPER = 1;
	public static final int SCISSOR = 2;


	public boolean dominates(Body b) {
		return 
		(this.getType()==ROCK && b.getType()==SCISSOR)
		||
		(this.getType()==PAPER && b.getType()==ROCK)
		||
		(this.getType()==SCISSOR && b.getType()==PAPER);
		
	}

	public int getType() {
		return type;
	}
	
	public String toString()
	{
		String typeName;
		if(type==ROCK)typeName="rock";
		else if(type==PAPER)typeName="paper";
		else if(type==SCISSOR)typeName="scissor";
		else throw new Error();
		return name+":"+team+","+typeName+","+HP+"HP";
	}

	public void inflictInjure(int i) {
		HP-=i;
	}

	public boolean isDead() {
		return HP<=0;
	}

	public String getName() {
		return name;
	}

	@Override
	public String consolePrint() {
		String res;
		
		if(type==ROCK)res= "r";
		else if(type==PAPER)res= "p";
		else res= "c";
		if(team.endsWith("1"))
			res=res.toUpperCase();
		return res;
	}

	public String getTeam() {
		return team;
	}
	
	 private void writeObject(java.io.ObjectOutputStream out)
     throws IOException
     {
		 out.writeInt(HP);
		 out.writeObject(name);
		 out.writeObject(team);
		 out.writeInt(type);
     }
 private void readObject(java.io.ObjectInputStream in)
     throws IOException, ClassNotFoundException
     {
	 HP=in.readInt();
	 name=(String)in.readObject();
	 team=(String)in.readObject();
	 type=in.readInt();
     }

		
}
